package com.spit.hkpost.bean.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.spit.hkpost.bean.db.RfidBean

/**
 * @Author nike
 * @Date 2023/9/6 17:42
 * @Description
 */
@Dao
interface RfidDao {

    /**
     * 增加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun add(vararg bean: RfidBean)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addAll(rfidBeans: List<RfidBean>)

    /**
     * 获取全部
     */
    @Query("SELECT * FROM RfidBean")
    fun findAll(): List<RfidBean>

    @Query("SELECT * FROM RfidBean WHERE epc = :epc")
    fun findById(epc: String): RfidBean

    @Query("SELECT * FROM RfidBean WHERE epc = :epc AND today = :today")
    fun findById(epc: String, today: String): RfidBean

    @Query("SELECT * FROM RfidBean WHERE today = :today")
    fun findTimeAll(today: String): List<RfidBean>

    /**
     * 根据用户ID删除全部
     */
    @Query("DELETE FROM RfidBean WHERE parentId = :parentId")
    suspend fun deleteParentId(parentId: Long)

    /**
     * 更新
     */
    @Update
    fun update(bean: RfidBean)

    /**
     * 根据主键删除全部
     */
    @Delete
    suspend fun deleteById(bean: RfidBean)

    @Query("delete from RfidBean")
    suspend fun deleteAll()

}